package com.jhhc.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间转化工具
 * @author suxuelian
 */
public class DateConvertUtil {


    public static long getTimeStamp(int timestampType) {
        Date date1 = new Date();
        long times = date1.getTime();
        if (timestampType == 1)
        {
            times = times/1000L;
        }
        return  times;
    }


    public Date getDateTime(long timestamp,int timestampType)
    {
        if (timestampType == 1)
        {
            //如果时间戳格式是秒，需要江时间戳变为毫秒
            timestamp = timestamp * 1000L;
        }
        Date dateTime = new Date(timestamp);
        return  dateTime;

    }


    public String getDateTimeString(Date date,String format )
    {
        if (format == null || format.length() <=0)
        {
            return  null;
        }
        // 格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String timeString = sdf.format(date);
        return  timeString;
    }


    public String getTimeStampString(long timestamp,String format ,int timestampType)
    {
        if (format == null || format.length() <=0)
        {
            return  null;
        }
        if (timestampType == 1)
        {
            //如果时间戳格式是秒，需要江时间戳变为毫秒
            timestamp = timestamp * 1000L;
        }
        Date dateTime = new Date(timestamp);
        // 格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String timeString = sdf.format(dateTime);
        return  timeString;
    }

}